﻿using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ManYan.Common
{
    public class DynamicSql
    {

        public List<ItemSetting>? itemSettings { get; set; }

        public string this[int index]
        {
            get
            {
                if (itemSettings != null)
                    return Convert(itemSettings[index]);
                else
                    return string.Empty;
            }
        }

       

        /// <summary>
        /// 通过属性过滤器处理掉所有的sql拼接
        /// </summary>
        public string SearchSql
        {
            get
            {
                StringBuilder stringBuilder = new StringBuilder();
                if(itemSettings!=null)
                for (int i=0;i<=itemSettings.Count;i++)
                {
                        stringBuilder.Append(this[i]);
                }
                return stringBuilder.ToString();
            }
        }

        public static string Convert(ItemSetting item)
        {
            return string.Empty;
        }

    }

    public class ItemSetting
    {
        [Required]
        public OT oT { get; set; }

        [Required]
        public QueryModel? queryModel { get; set; }

    }


    public class QueryModel
    {
        [Required]
        public string? TableColumnName { get; set; }
        public object[]? ColumnValue { get; set; }



        public QT qT { get; set; }
        /// <summary>
        /// 如果查询的条件值有多个，可以要获取第N个。如做in查询，理论上是where name in('1','2'),所以对于数组过来的in要加单引号
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public object this[int index]
        {
            get
            {
                if (ColumnValue == null)
                    throw new Exception("数据长度不能为空");
                if (ColumnValue.Length - 1 >= index)
                    return ColumnValue[index];
                else
                    throw new Exception("数据异常");
            }
        }


    }
    /// <summary>
    /// 拼接类型
    /// </summary>
    public enum OT
    {
        /// <summary>
        /// 两个条件做end
        /// </summary>
        and = 0,
        /// <summary>
        /// 两个条件做or
        /// </summary>
        or = 1,
        /// <summary>
        /// 单条件
        /// </summary>
        Null = 2
    }
    /// <summary>
    /// 数据查询操作
    /// </summary>
    public enum QT
    {
        #region Like操作
        /// <summary>
        /// 前缀like如%xx
        /// </summary>
        preLike = 0,
        /// <summary>
        /// like 如 %XX%
        /// </summary>
        like = 1,
        /// <summary>
        /// 后缀查询如 xx%
        /// </summary>
        sufLike = 2,
        #endregion
        /// <summary>
        /// 等于
        /// </summary>
        eq = 3,
        /// <summary>
        /// 大于
        /// </summary>
        greater = 4,
        /// <summary>
        /// 小于
        /// </summary>
        less = 5,
        /// <summary>
        /// 区间
        /// </summary>
        betwwen = 6,
        /// <summary>
        /// 不等于
        /// </summary>
        noequal = 7,
        /// <summary>
        /// in
        /// </summary>
        ins = 8


    }

    public abstract class Testabsract
    {

        public abstract void Test();

        public  string Test1()
        {
            return string.Empty;
        }
    }

    public class TestAbstractChildren : Testabsract,ITestabstract
    {
        public override void Test()
        {
            throw new NotImplementedException();
        }

        public void Test11()
        {
            throw new NotImplementedException();
        }
    }

    public interface ITestabstract
    {
        public void Test11();

        public string Test2()
        {
            return string.Empty;
        }
    }

 


}
